package com.niit.userinterface;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    String[] contacts = {"张三","李四","王五","赵六","小米","小红","小天"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 1.先找到ListView控件,通过findViewById()方法
        ListView listView = findViewById(R.id.lv);

        // 2.创建适配器
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,contacts);

        // 3.给ListView控件设置适配器
        listView.setAdapter(adapter);


    }
}